<?php

namespace app\controller\Admin;

use think\facade\Db;
use think\facade\Request;

class BusinessCooperation
{
    /**
     * 获取商务合作文章列表
     * @return \think\response\Json
     */
    public function getArticles()
    {
        $articles = Db::table('business_cooperation_articles')->select();
        return json($articles);
    }

    /**
     * 保存商务合作文章
     * @return \think\response\Json
     */
    public function saveArticle()
    {
        $data = Request::post();
        $id = Db::table('business_cooperation_articles')->insertGetId($data);
        return json(['code' => 200, 'msg' => '保存成功', 'id' => $id]);
    }

    /**
     * 更新商务合作文章
     * @param $id
     * @return \think\response\Json
     */
    public function updateArticle($id)
    {
        $data = Request::post();
        Db::table('business_cooperation_articles')->where('id', $id)->update($data);
        return json(['code' => 200, 'msg' => '更新成功']);
    }

    /**
     * 删除商务合作文章
     * @param $id
     * @return \think\response\Json
     */
    public function deleteArticle($id)
    {
        Db::table('business_cooperation_articles')->where('id', $id)->delete();
        return json(['code' => 200, 'msg' => '删除成功']);
    }
}
